package com.killuasy.utils.io;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;

import com.killuasy.utils.SysInit;

public class OutPutFile {
	public static boolean outPutLinkFile(String path, ArrayList<String> outPutList) {
		boolean resultFlag = false;

		File f = new File(path);

		try {
			if (!f.exists())
				f.createNewFile();

			FileOutputStream fos = new FileOutputStream(path);
			OutputStreamWriter osw = new OutputStreamWriter(fos);
			BufferedWriter bw = new BufferedWriter(osw);
			
			String outPutStr=null;
			DecimalFormat df=new DecimalFormat("0000");

			for (int i=0;i<outPutList.size();i++) {
				outPutStr=outPutList.get(i);
				
				bw.write(SysInit.linkStrStart);
				bw.write(outPutStr);
				bw.write(SysInit.linkStrMiddle);
				bw.write(df.format(i+1));
				bw.write(SysInit.linkStrEnd);
				bw.write(SysInit.linkBR);
				bw.newLine();
			}
			
			bw.close();
			osw.close();
			fos.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return resultFlag;
	}
}
